﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SMSManage_SMSGroupSend : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btOK_Click(object sender, EventArgs e)
    {
        using (DAL.CMSDALDataContext dataContext = new DAL.CMSDALDataContext())
        {
            DAL.BI_User dUser = dataContext.BI_User.FirstOrDefault(o => o.UserCode == tbLogin1.Text && o.Pwd == tbPassword1.Text);
            if (dUser != null)
            {
                //用户一权限
                string[] rights1 = dUser.Rights.Split('|');

                if (rights1.Contains("5005") || dUser.IsAdmin == 1)
                {
                    DAL.BI_User dUser2 = dataContext.BI_User.FirstOrDefault(o => o.UserCode == tbLogin2.Text && o.Pwd == tbPassword2.Text);
                    if (dUser2 != null)
                    {
                        //用户二权限
                        string[] rights2 = dUser2.Rights.Split('|');

                        if (rights2.Contains("5005") || dUser2.IsAdmin == 1)
                        {
                            //用户一和用户二不是同个用户
                            if (dUser2.UserID != dUser.UserID)
                            {
                                foreach (DAL.BI_Consumer consumer in dataContext.BI_Consumer.ToList())
                                {
                                    WebUtility.InsertSMS(consumer.ConsumerID, DateTime.Now, mo_SMS.Text, 0);
                                }
                                //清空
                                cbo_SMS.Text="";
                                mo_SMS.Text="";
                                Frame.Global.GlobalFunctions.Alert("短信保存成功!");
                            }
                        }
                    }
                }
            }
        }
    }
}